package com.example.book.controller;

import com.example.book.config.messageconverter.MyWebConfig;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * 压力测试 使用异步和不使用异步的吞吐量有多大区别
 *
 * @author wb-ys274743
 * @Date 2018/8/27
 */
@RestController
public class JmeterAbContoller {

    @RequestMapping("/syncTest")
    public String syncTest() {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
        }
        return "END";
    }

    // 比同步返回吞吐量大概提高10%
    @RequestMapping("/asyncTest")
    public Future<String> asyncTest() {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
            }
            return "END";
        }, MyWebConfig.executorService);
        return future;
    }

}
